package org.netEase.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.netEase.dao.*;
import org.netEase.dao.impl.*;
import org.netEase.entity.*;
import org.netEase.util.pageBean;



@WebServlet(urlPatterns = { "/backstageManager/comments.shtml" })
public class comments extends HttpServlet{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	request.setCharacterEncoding("utf-8");
	commentDao commentDao = new commentDaoImple();
	pageBean pageBean = new pageBean(); 
	int condition =commentDao.getCount();
	pageBean.setTotal(condition);
	String pageStr = request.getParameter("p");
	if(pageStr != null){
		pageBean.setPageNo(Integer.parseInt(pageStr));
	}
	
	
	List<comment> comment=commentDao.getall(pageBean.getPageNo(),pageBean.getSize());
	request.setAttribute("comment",comment);
	request.setAttribute("pageBean", pageBean);
	request.getRequestDispatcher("/backstageManager/feedback-list.jsp").forward(request, response);
}
@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	request.setCharacterEncoding("utf-8");
	String hid = request.getParameter("hid");
	String coid=request.getParameter("coid");
	String rtext=request.getParameter("rtext");
	reply er= new reply();
	er.setHid(Integer.parseInt(hid));
	er.setCoid(Integer.parseInt(coid));
	er.setRtext(rtext);
	replyDao reDao=new replyDaoImpl();
	int re=reDao.add(er);
	if(re > 0){
		response.sendRedirect(request.getContextPath() + "/backstageManager/comments.shtml");
	}
	
		
		
	
	
	
	}
}
